package Topic;

import Utils.ConnectionFactoryUtil;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
  *@ClassName ConsumerMail
  *@Description TDD
  *@Author 混沌酱
  *@Date 2023-10-10 17:22
  *@Version 1.0
  **/
public class ConsumerMail {

    public static void main(String[] args) throws IOException, TimeoutException {
        //1 、建立工厂连接
        Connection connection= ConnectionFactoryUtil.getConnection();

        //2、构建channel
        Channel channel=connection.createChannel();

        channel.basicConsume("SEND_MAIL3",true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                super.handleDelivery(consumerTag, envelope, properties, body);
                String message = new String(body, "UTF-8");
                System.out.println(message);
            }
        });
    }
}
